package com.spring.mvc.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.mapping.StatementType;
import org.springframework.stereotype.Repository;

import com.spring.mvc.pojo.User;

@Repository
public interface UserMapper {
	
	/**
	 * Check user name isExists
	 * @param userName
	 * @return
	 */
	@Select("select * from t_user t where t.username=#{userName}")
	public User checkUserName(String userName);

	/**
	 * user login
	 * @param userName
	 * @param userPwd
	 * @return
	 */
	@Select("select * from t_user t where t.username=#{userName} and t.userpwd=#{userPwd}")
	public List<User> login(@Param("userName")String userName, @Param("userPwd")String userPwd);

	/**
	 * user register
	 * @param user
	 * @return
	 */
	@SelectKey(before = true, keyProperty = "id", resultType = java.lang.Integer.class, 
			statement = { "select t_user_sequences.nextval as id from dual" },
			statementType=StatementType.STATEMENT)
	@Insert("insert into t_user(id,username,userpwd,createTime,email,phone,mobile,address,age,ipAddr) " +
			"values(#{id},#{userName},#{userPwd},sysdate,#{email},#{phone},#{mobile},#{address},#{age},#{ipAddr})")
	public int insert(User user);

	/**
	 * query user List
	 * @return
	 */
	@Select("select * from t_user t ")//where t.createtime>to_date(#{startTime},'yyyy-mm-dd hh24:mi:ss') " +
	//"and t.createtime<to_date(#{endTime},'yyyy-mm-dd hh24:mi:ss')
	public List<User> list();
	
}
